/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package logic;

/**
 *
 * @author kotionokyurievna
 */
public class MetroCardRechargeable extends MetroCard{
    private double money;
    
    public MetroCardRechargeable( CardDataBase cardDb){
        super();
        setType(CardType.NORMAL);
        money = 0;
        setPassChecker(new MoneyPassChecker(this, cardDb));
    }
    
    public MetroCardRechargeable( double money, CardDataBase cardDb){
        this(cardDb);
        setMoney(money);
    }
    
    
    public double getMoney(){
        return money;
    }
    
    private void setMoney( double money){
        addMoney(money);
    }
    
   
    @Override
    public boolean addMoney( double money ){
        if ( money > 0){
            this.money += money;
            return true;
        }
        return false;
    }
    
    public boolean subMoney( double amount ){
        if ( ( amount > 0 ) && ( amount <= this.money ) ){
            this.money -= amount;
            return true;
        }
        return false;
    }
}
